import { isUrl } from '../utils/utils';
import { getAuthority } from '../utils/authority';

const menuData = [
  {
    name: '设备管理',
    icon: 'dashboard',
    path: 'dashboard',
    authority: 's1_02',
    children: [
      {
        name: '车队地图',
        path: 'monitor',
        authority: 's1_0201',
      },
      {
        name: '设备列表',
        path: 'devlist',
        authority: 's1_0202',
      },
      {
        name: '车辆时长',
        path: 'vehperiod',
      },
      {
        name: '设备详情',
        path: 'devdetail',
        hideInMenu: true,
      },
      {
        name: '流量控制',
        path: 'flowlist',
        hideInMenu: true,
      },
      {
        name: '设备轨迹',
        path: 'devtrack/init',
        hideInMenu: true,
      },
      {
        name: '流量监控',
        path: 'simcard',
      },
      {
        name: '流量监控详情',
        path: 'simcarddetail',
        hideInMenu: true,
      },
    ],
  },
  {
    name: '素材管理',
    icon: 'picture',
    path: 'matter',
    authority: 's1_03',
    children: [
      {
        name: '素材列表',
        path: 'matterlib',
        authority: 's1_0301',
      },
      {
        name: '素材模版',
        path: 'cutinlib',
      },
      {
        name: '编辑区域',
        path: 'geolib',
        hideInMenu: true,
      },
      {
        name: '素材审核',
        path: 'detail',
        hideInMenu: true,
      },
    ],
  },
  {
    name: '节目管理',
    icon: 'profile',
    path: 'program',
    authority: 's1_04',
    children: [
      {
        name: '节目列表',
        path: 'programlist',
        authority: 's1_0401',
      },
      {
        name: '播放列表',
        path: 'playlist',
      },
      {
        name: '区域列表',
        path: 'arealist',
      },
      {
        name: '插播列表',
        path: 'cutinlist',
      },
      {
        name: '任务中心',
        path: 'tasklist/init',
        hideInMenu: true,
      },
      {
        name: '添加素材',
        path: 'basic-list',
        hideInMenu: true,
      },
      {
        name: '节目审核',
        path: 'programdetail',
        hideInMenu: true,
      },
    ],
  },
  {
    name: '设备日志',
    icon: 'form',
    path: 'devlog',
    authority: 's1_04',
    children: [
      {
        name: '操作日志',
        path: 'devtask/init',
      },
      {
        name: '发布日志',
        path: 'tasklist/init',
      },
      {
        name: '插播日志',
        path: 'cutinlog/init',
      },
    ],
  },
  {
    name: '设备维护',
    icon: 'profile',
    path: 'devmaintain',
    authority: 's1_04',
    children: [
      // {
      //   name: '设备测试',
      //   path: 'devtest',
      //   authority: 's1_0401',
      // },
      {
        name: '设备报修',
        path: 'devfix',
      },
      {
        name: '设备升级',
        path: 'devupdate',
      },
      {
        name: '设备报警',
        path: 'devalarm',
      },
    ],
  },
  {
    name: '系统设置',
    icon: 'setting',
    path: 'usermanage',
    authority: 's1_05',
    children: [
      {
        name: '用户资料',
        path: 'profile',
        authority: 's1_0501',
      },
      {
        name: '用户管理',
        path: 'acmanage',
        authority: 's1_0502',
      },
      {
        name: '角色管理',
        path: 'rolemanage',
        authority: 's1_0503',
      },
      {
        name: '账号安全',
        path: 'resetpwd',
        authority: 's1_0504',
      },
      {
        name: '联系我们',
        path: 'contactus',
      },
    ],
  },
  {
    name: '异常页',
    icon: 'warning',
    path: 'exception',
    hideInMenu: true,
    children: [
      {
        name: '403',
        path: '403',
      },
      {
        name: '404',
        path: '404',
      },
      {
        name: '500',
        path: '500',
      },
      {
        name: '触发异常',
        path: 'trigger',
        hideInMenu: true,
      },
    ],
  },
];
const menuToken = getAuthority();
function formatter(data, token, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    const authArray = token.split(',');
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(
        item.children,
        token,
        `${parentPath}${item.path}/`,
        item.authority,
        token
      );
    }

    return result;
  });
}

export const getMenuData = () => formatter(menuData, menuToken);
